package com.shop.loan.controller;

import com.shop.loan.model.Question;
import com.shop.loan.model.common.Code;
import com.shop.loan.model.common.Constant;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.vo.ChannelOpenVo;
import com.shop.loan.model.vo.HomeResVo;
import com.shop.loan.model.vo.UFileVo;
import com.shop.loan.model.vo.UserLoginVo;
import com.shop.loan.qiniu.QiNiuUtil;
import com.shop.loan.service.QuestionService;
import com.shop.loan.service.SettingService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(value = "系统设置", tags = "系统设置")
@RestController
@RequestMapping(Constant.appPrefex + "/setting")
public class SettingController {

    @Resource
    SettingService settingService;

    @Resource
    QiNiuUtil qiNiuUtil;

    @Resource
    QuestionService questionService;


    @ApiOperation(value = "首页接口")
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功", response = HomeResVo.class)
    })
    @PostMapping("/home")
    public ResResult home(UserLoginVo userLoginVo) {
        return settingService.home(userLoginVo);
    }


    @PostMapping("/open")
    public ResResult open(ChannelOpenVo channelOpenVo) {
        return settingService.open(channelOpenVo);
    }


//    @ApiOperation(value = "文件上传token")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "key", value = "保存的文件名", dataType = "string"),
//    })
//    @PostMapping("/file/token")
//    public ResResult token(@ApiIgnore UFileVo ufileVo) throws Exception {
//        return new ResResult(Code.SUCCESS, qiNiuUtil.getUpToken(ufileVo.getKey()));
//    }


    @ApiOperation(value = "问题列表")
    @PostMapping("/question/list")
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功", response = Question.class)
    })
    public ResResult questionList(@ApiIgnore UFileVo ufileVo) throws Exception {
        return new ResResult(Code.SUCCESS, questionService.list());
    }

}
